<include file="Public/popHeader" />
<body class="hold-transition skin-blue sidebar-mini">
        <div class="row"><div class="col-md-12">
        <div class="box box-info">
            <div class="box-header with-border">
                <h3 class="box-title">店铺运费模板</h3>
            </div>
            <!-- /.box-header -->
            <!-- form start -->
            <form id="form" method="post" accept-charset="UTF-8" class="form-horizontal">
                <input type="hidden" name="id" value="{$info.id}">
                <input type="hidden" name="tmp_id" value="{$tmp_id}">
                <div class="box-body">
                    <div class="form-group 1">
                        <label class="col-sm-2 control-label">区域名称</label>
                        <div class="col-sm-6">
                            <div class="input-group">
                                <span class="input-group-addon"><i class="fa fa-pencil"></i></span>
                                <input type="text" name="qyname" id="qyname" value="{$info.qyname}" class="form-control" placeholder="区域名称">
                            </div>
                        </div>
                    </div>
                    <div class="form-group 1">
                        <label class="col-sm-2 control-label">首重</label>
                        <div class="col-sm-6">
                            <div class="input-group">
                                <span class="input-group-addon"><i class="fa fa-pencil"></i></span>
                                <input type="text" name="firstunit" id="firstunit" value="{$info.firstunit}" class="form-control" placeholder="首重">
                                <span class="input-group-addon">Kg</span>
                            </div>
                        </div>
                    </div>
                    <div class="form-group 1">
                        <label class="col-sm-2 control-label">首重运费</label>
                        <div class="col-sm-6">
                            <div class="input-group">
                                <span class="input-group-addon"><i class="fa fa-pencil"></i></span>
                                <input type="text" name="firstprice" id="firstprice" value="{$info.firstprice}" class="form-control" placeholder="首重运费">
                                <span class="input-group-addon">元</span>
                            </div>
                        </div>
                    </div>
                    <div class="form-group 1">
                        <label class="col-sm-2 control-label">续重</label>
                        <div class="col-sm-6">
                            <div class="input-group">
                                <span class="input-group-addon"><i class="fa fa-pencil"></i></span>
                                <input type="text" name="continueunit" id="continueunit" value="{$info.continueunit}" class="form-control" placeholder="续重">
                                <span class="input-group-addon">Kg</span>
                            </div>
                        </div>
                    </div>
                    <div class="form-group 1">
                        <label class="col-sm-2 control-label">续重费</label>
                        <div class="col-sm-6">
                            <div class="input-group">
                                <span class="input-group-addon"><i class="fa fa-pencil"></i></span>
                                <input type="text" name="continueprice" id="continueprice" value="{$info.continueprice}" class="form-control" placeholder="续重费">
                                <span class="input-group-addon">元</span>
                            </div>
                        </div>
                    </div>

                </div>
                <!-- /.box-body -->
                <div class="box-footer">
                    <div class="col-sm-2"></div>
                    <div class="col-sm-6">
                        <div class="btn-group pull-left">
                            <button type="submit" class="btn btn-info pull-right batch-choose">提交</button>
                        </div>
                    </div>
                </div>
                <!-- /.box-footer -->
            </form>
        </div>

    </div></div>

</body>
<!-- 底部 -->
<!-- Bootstrap 3.3.6 -->
<script src="Public/admin/adminlte/bootstrap/js/bootstrap.min.js"></script>
<!-- QgsLTE App -->
<script src="Public/admin/adminlte/dist/js/app.min.js"></script>
<!-- QgsLTE for demo purposes -->
<script src="Public/admin/adminlte/dist/js/demo.js"></script>
<script src="Public/admin/adminlte/plugins/iCheck/icheck.min.js"></script>
<script type="text/javascript">
    $(function () {
        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
		var isAjaxSend = false;
		//表单验证
		$("#form").validate({
			rules: {
				qyname:{
					required: true,
					rangelength: [2, 50]
				},
				firstunit:{
					required: true,
					isPrice: true,
					min:0.01
				},
				firstprice:{
					required: true,
					isPrice: true,
					min:0.01
				},
				continueunit:{
					required: true,
					isPrice: true,
					min:0.01
				},
				continueprice:{
					required: true,
					isPrice: true,
					min:0.01
				}
			},
			messages:{
				qyname: {
					required: "请输入区域名称"
				},
				firstunit: {
					required: "请输入首重"
				},
				firstprice: {
					required: "请输入首重运费"
				},
				continueunit: {
					required: "请输入续重"
				},
				continueprice: {
					required: "请输入续重费"
				}
			},
			submitHandler: function(form){
				if(!isAjaxSend){
					isAjaxSend = true;
					ajaxSaveData();
				}
			}
		});
        function ajaxSaveData(){
			GPopup.loadDialog();
            var data = [];
            var exists = parent.$('.ui-sortable').find('li input');
            var exists_ids = [];
            exists.each(function () {
                exists_ids.push($(this).val());
            });

            var qyname = $('#qyname').val();
            var firstunit = $('#firstunit').val();
            var firstprice = $('#firstprice').val();
            var continueunit = $('#continueunit').val();
            var continueprice = $('#continueprice').val();
            var values = qyname+ '-' + firstunit + '-' + firstprice + '-' + continueunit + '-' + continueprice;
            var id = $('input[name=id]').val();
            var tmp_id = $('input[name=tmp_id]').val();

            $.ajax({
                type: "post",
                url: "{:U('Freight/dlytmpAreaAdd','')}",
                data: {id: id, tmp_id:tmp_id, qyname:qyname,firstunit:firstunit,firstprice:firstprice,continueunit:continueunit,continueprice:continueprice},
                success: function (msg) {
					isAjaxSend = false;
					GPopup.removeLoad();
                    if (id) {
                        parent.$('.zyf_'+id).children("input[name='value[]']").val(values + '-' +id);
                        parent.$('.zyf_'+id).children('small:eq(0)').text(' 区域名称 : '+qyname);
                        parent.$('.zyf_'+id).children('small:eq(1)').text(' 首重 : '+firstunit+'Kg');
                        parent.$('.zyf_'+id).children('small:eq(2)').text(' 首重运费 : '+firstprice+'元');
                        parent.$('.zyf_'+id).children('small:eq(3)').text(' 续重 : '+continueunit+'Kg');
                        parent.$('.zyf_'+id).children('small:eq(4)').text(' 续重费 : '+continueprice+'元');
						parent.layer.close(index);
                    } else {
                        var html = '';
                        html += '<li class="zyf_'+msg.data+'">';
                        values = values + '-' +msg.data;
                        html += '<input type="hidden" name="value[]" value="'+values+'">';
                        html += '<span class="handle ui-sortable-handle">';
                        html += '<i class="fa fa-ellipsis-v"></i>\n\r';
                        html += '<i class="fa fa-ellipsis-v"></i>';
                        html += '</span>\n\r';
                        html += '<small class="label label-warning"> 区域名称 : '+qyname+'</small>\n\r';
                        html += '<small class="label label-success"> 首重 : '+firstunit+' kg</small>\n\r';
                        html += '<small class="label label-success"> 首重运费 : '+firstprice+' 元</small>';
                        html += '<small class="label label-info"> 续重 : '+continueunit+' kg</small>';
                        html += '<small class="label label-info"> 续重费 : '+continueprice+' 元</small>';
                        html += '<div class="label"><a href="javascript:void(0)" class="add_area" id="'+msg.data+'">添加地区</a></div>';
                        html += '<div class="tools">';
                        html += '<i class="fa fa-pencil iconedit" data-id="'+msg.data+'"></i>';
                        html += '<i class="fa fa-trash-o icondel" data-id="'+msg.data+'"></i>';
                        html += '</div>';
                        html += '</li>';

                        parent.$('.ui-sortable').append(html);
                        parent.$('.col-sm-offset-2').removeClass('hide');
                        parent.layer.close(index);
                    }
                },
                error: function (msg) {
					GPopup.removeLoad();
					isAjaxSend = false;
                    alert(msg.message);
                }
            });
		}
	});
</script>
</html>

